package com.dy.design_pattern_study.memento_pattern.dome3;

import lombok.Data;

/**
 * @CreateBy zhangdingyi
 * @Date 2023-04-11
 * @Content 游戏角色类
 */
@Data
public class GameRole {
    /**
     * 体力
     */
    private int vit;
    /**
     * 攻击力
     */
    private int atk;
    /**
     * 防御力
     */
    private int def;

    /**
     * 状态显示
     */
    public void stateDisplay() {
        System.out.println("当前角色状态：");
        System.out.println("体力 = " + vit);
        System.out.println("攻击力 = " + atk);
        System.out.println("防御力 = " + def);
        System.out.println("--------------");
    }

    /**
     * 获得初始状态
     */
    public void getInitState() {
        //数据通常来自数据库 或者本机缓存
        vit = 100;
        atk = 100;
        def = 100;
    }

    /**
     * 战斗后状态减少
     */
    public void fight() {
        vit = 0;
        atk = 0;
        def = 0;
    }

    /**
     * 保存状态
     * @return
     */
    public GameMemento saveState() {
        return new GameMemento(vit, atk, def);
    }

    /**
     * 还原状态
     * @param gameMemento
     */
    public void recoveryState(GameMemento gameMemento) {
        vit = gameMemento.getVitMemento();
        atk = gameMemento.getAtkMemento();
        def = gameMemento.getDefMemento();

    }
}
